package com.chushouya.manager.dao.repository;

import com.chushouya.manager.dao.entity.RoleMenuEntity;
import com.chushouya.manager.dao.mapper.RoleMenuEntityMapper;
import com.general.framework.data.mybatis.BaseRepository;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Repository
public class RoleMenuRepository extends BaseRepository<RoleMenuEntityMapper, RoleMenuEntity, Long> {

    public List<RoleMenuEntity> selectRoleMenuByRoleIdList(List<Long> roleIdList) {
        Example example = this.buildExample();
        example.and().andIn("roleId", roleIdList);
        return this.selectByExample(example);
    }

    public int selectMenuInRoleCount(Long menuId) {
        Example example = this.buildExample();
        example.and().andEqualTo("menuId", menuId);
        return this.selectCountByExample(example);
    }

    public void deleteByRoleId(Long roleId) {
        Example example = this.buildExample();
        example.and().andEqualTo("roleId", roleId);
        this.deleteByExample(example);
    }
}
